/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.memberView;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.SwingUtil;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.view.base.BaseInternalFrame;
import com.ruipengkj.view.giftView.GiftPanel;
import com.ruipengkj.view.workShiftView.WorkShiftPanel;
import com.ruipengkj.view.workShiftView.WorkShiftTakeNotesPanel;

/**
 * 说明：
 * 会员主窗体
 * @Author：李智深
 * @Date：2012-03-15
 */
public class MemberInternalFrame extends BaseInternalFrame{

	private static final long serialVersionUID = 1L;
	
	private JToolBar toolBar;//工具栏
	
	private JPanel main;//主面板
	private CardLayout main_layout;//主面板布局
	

	
	private JButton fillCardButton;//会员充值按钮
	private MemberFillCardPanel menberFillCardPanel;//会员充值面板
	
	private JButton queryCardButton;//会员卡查询按钮
	private MemberQueryCardPanel meberQueryCardPanel;//会员卡查询面板
	
	private JButton createCardBttton;//发卡按钮
	private MemberCreateCardPanel menberCreateCardPanel; //发卡面板
	
	private JButton giftFrameButton;//会员领取礼包按钮
	private MemberGiftPanel menberGiftPanel;//会员领取礼包面板
	
	private JButton lostCardFrameButton;//补卡补卡按钮
	private MemberLostCardPanel menberLostCardPanel;//会员补卡面板
	
	private JButton levelManagerButton;//级别管理按钮
	private MemberLevelManagePanel memberLevelManagePanel;//会员级别管理面板
	
	private JButton workShiftButton;
	private WorkShiftPanel workShiftPanel;
	
	private JButton workShiftTakeNotesButton;
	private WorkShiftTakeNotesPanel workShiftTakeNotesPanel;
	
	private JButton giftButton;
	private GiftPanel giftPanel;
	
	public MemberInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable,boolean iconifiable){
		super(title, resizable, closable, maximizable,iconifiable);
		this.init();
	}
	
	private void init(){
		this.setLayout(new BorderLayout());
		this.initViews();
		this.initListener();
	}
	
	//初始化组件
	private void initViews(){
		toolBar = new JToolBar();
		toolBar.setFloatable(false);//设置工具栏不可移动
		
		createCardBttton=new JButton("发卡",SwingUtil.getOpenSwingImage("member_card_the issuing.png"));
		lostCardFrameButton=new JButton("补卡",SwingUtil.getOpenSwingImage("member_card_replacement.png"));
		queryCardButton=new JButton("会员卡查询",SwingUtil.getOpenSwingImage("member_ card_query.png"));
		fillCardButton=new JButton("会员卡充值",SwingUtil.getOpenSwingImage("member_ card_recharge.png"));
		giftFrameButton=new JButton("领取礼包",SwingUtil.getOpenSwingImage("member_card_receive_package.png"));
		levelManagerButton=new JButton("级别管理",SwingUtil.getOpenSwingImage("member_card_receive_package.png"));
		workShiftButton = new JButton("交班",SwingUtil.getOpenSwingImage("member_card_the issuing.png"));
		giftButton = new JButton("添加礼品信息",SwingUtil.getOpenSwingImage("member_card_the issuing.png"));
		workShiftTakeNotesButton = new JButton("交班记录",SwingUtil.getOpenSwingImage("member_card_the issuing.png"));
		
		
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL21)){
			toolBar.add(createCardBttton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL22)){
			toolBar.add(lostCardFrameButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL23)){
			toolBar.add(queryCardButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL24)){
			toolBar.add(fillCardButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL25)){
			toolBar.add(giftFrameButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL26)){
			toolBar.add(levelManagerButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL27)){
			toolBar.add(giftButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL28)){
			toolBar.add(workShiftButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL29)){
			toolBar.add(workShiftTakeNotesButton);
		}
		
		main=new JPanel();
		main_layout=new CardLayout();
		main.setLayout(main_layout);
		this.add(toolBar,BorderLayout.NORTH);
		this.add(main,BorderLayout.CENTER);
	}
	
	//初始化监听器
	private void initListener(){
		fillCardButton.addActionListener(this);
		queryCardButton.addActionListener(this);
		createCardBttton.addActionListener(this);
		giftFrameButton.addActionListener(this);
		levelManagerButton.addActionListener(this);
		lostCardFrameButton.addActionListener(this);
		giftButton.addActionListener(this);
		workShiftButton.addActionListener(this);
		workShiftTakeNotesButton.addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==createCardBttton){
			//发卡按钮
			menberCreateCardPanel=new MemberCreateCardPanel();
			main.add(menberCreateCardPanel,"menberCreateCardPanel");
			main_layout.show(main, "menberCreateCardPanel");
			this.setTitle("会员管理--发  卡");
			Util.setButtonStatus(toolBar,createCardBttton);
		}else if(e.getSource()==lostCardFrameButton){
			//补卡按钮
			menberLostCardPanel=new MemberLostCardPanel();
			main.add(menberLostCardPanel,"menberLostCardPanel");
			main_layout.show(main, "menberLostCardPanel");
			this.setTitle("会员管理--补  卡");
			Util.setButtonStatus(toolBar,lostCardFrameButton);
		}else if(e.getSource()==queryCardButton){
			//会员卡查询按钮
			meberQueryCardPanel=new MemberQueryCardPanel();
			main.add(meberQueryCardPanel,"meberQueryCardPanel");
			main_layout.show(main, "meberQueryCardPanel");
			this.setTitle("会员管理--会员卡查询");
			Util.setButtonStatus(toolBar,queryCardButton);
			SwingUtilities.invokeLater(meberQueryCardPanel);
		}else if(e.getSource()==fillCardButton){
			//会员卡充值按钮
			menberFillCardPanel=new MemberFillCardPanel();
			main.add(menberFillCardPanel,"menberFillCardPanel");
			main_layout.show(main, "menberFillCardPanel");
			this.setTitle("会员管理--会员卡充值");
			Util.setButtonStatus(toolBar,fillCardButton);
		}else if(e.getSource()==giftFrameButton){
			//领取礼包按钮
			menberGiftPanel=new MemberGiftPanel();
			main.add(menberGiftPanel,"menberGiftPanel");
			main_layout.show(main, "menberGiftPanel");
			this.setTitle("会员管理--领取礼包");
			Util.setButtonStatus(toolBar,giftFrameButton);
		}else if(e.getSource()==levelManagerButton){
			memberLevelManagePanel=new MemberLevelManagePanel();
			main.add(memberLevelManagePanel,"memberLevelManagePanel");
			main_layout.show(main, "memberLevelManagePanel");
			this.setTitle("会员管理--级别管理");
			Util.setButtonStatus(toolBar,levelManagerButton);
		}else if(e.getSource()==giftButton){
			giftPanel=new GiftPanel();
			main.add(giftPanel,"giftPanel");
			main_layout.show(main, "giftPanel");
			this.setTitle("会员管理--礼品列表");
			Util.setButtonStatus(toolBar,giftButton);
		}else if(e.getSource()==workShiftButton){
			workShiftPanel = new WorkShiftPanel();
			main.add(workShiftPanel,"workShiftPanel");
			main_layout.show(main, "workShiftPanel");
			this.setTitle("会员管理--交班");
			Util.setButtonStatus(toolBar,workShiftButton);
		}else if(e.getSource()==workShiftTakeNotesButton){
			workShiftTakeNotesPanel = new WorkShiftTakeNotesPanel();
			main.add(workShiftTakeNotesPanel,"workShiftTakeNotesPanel");
			main_layout.show(main, "workShiftTakeNotesPanel");
			this.setTitle("会员管理--交班");
			Util.setButtonStatus(toolBar,workShiftTakeNotesButton);
		}
		main.updateUI();
	}
	
	public void showButton(){
		if (toolBar != null && toolBar.getComponentCount() != 0)
			((JButton)toolBar.getComponent(0)).doClick();
	}
	
	public void showButton(int type){
		switch(type){
			case 1:{createCardBttton.doClick();break;}
			case 2:{lostCardFrameButton.doClick();break;}
			case 3:{queryCardButton.doClick();break;}
			case 4:{fillCardButton.doClick();break;}
			case 5:{giftFrameButton.doClick();break;}
			case 6:{levelManagerButton.doClick();break;}
			case 7:{giftButton.doClick();break;}
			case 8:{workShiftButton.doClick();break;}
			case 9:{workShiftTakeNotesButton.doClick();break;}
		}
	}
}
